All Questions
99 questions
0votes
4answers
120views
Why does this code write the answers more than once instead of just once?
I've just made a C program about finding perfect numbers. It is kinda working, but it writes out the answers more than once(and it writes 24 as well for some reason). I have very basic C knowledge, I ...
1vote
2answers
74views
C language pattern with unexpected result
I am trying to create a program in C to draw this pattern : 1 1 2 1 3 1 1 2 2 2 3 2 1 3 2 3 3 3 1 4 2 4 3 4 1 5 2 5 3 5 I checked the answer from solutions. #include <stdio.h> int main () { ...
2votes
1answer
34views
Modification pgm fill 2-D Array using a pointer and it doesn't work
Initial pgm void assign( int **mat, int n, int m ) { int **p = mat; int **p_end = p + n; for ( ; p < p_end; ++p ) { int *q = *p; int *q_end = q + m; for ( ; q < q_end; ++q ) { printf( ...
2votes
4answers
356views
Print numbers of a matrix in a wave pattern
I want the output to be 7 4 1 2 5 8 9 6 3 but it's coming out to be 1 4 7 2 5 8 3 6 9. How can I fix it, and what's the logic behind it so that I can print the reverse wave pattern, too? #include<...
1vote
3answers
130views
for loop in between if statement is not working in C
#include <stdio.h> int main() { int row, col, i, j; char ch; printf("Enter the Value of Row or Column: "); scanf("%d", &row); col = row; int mat[...
2votes
4answers
141views
How to exit an outer loop in C (without ++)?
In Java, it is possible to escape from an outer loop using such a construct: int[][] matrix; int value; ... outer: { for(int i=0; i<n; i++) for (int j=0; j<m; j++) if (matrix[i][j] ==...
1vote
1answer
550views
CS50 plurality, printing winner
bool vote(string name) { // TODO for (int i = 0; i < candidate_count; i++) { if (strcmp(candidates[i].name, name) == 0) //W's { candidates[i].votes++; ...
-1votes
2answers
48views
why outer for loop not completing whole in one go rather than passing control to inner for loop
why the outer for loop is not completing in first go rather than its passing control to inner for loop and the inner one is completing fully and then coming back with the previous value of outer for ...
0votes
2answers
118views
How to print a pyramidal pattern
#include<stdio.h> int main() { int n,i,j,k,m; printf("Enter the number of lines "); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=n-i;...
-1votes
1answer
50views
Unknown Segmentation fault Error while incrementing the index value in 2d array [closed]
There "Segmentation fault" error in the code. int hourglassSum(int arr_rows, int arr_columns, int** arr) { int sum=0,max=0; for(int i=0; i<arr_columns;i++){ for(int j=0; j&...
0votes
2answers
281views
C program for a reverse triangle pattern
I want to draw a pattern like this: 567898765 4567654 34543 232 1 But I can't seem to figure it out, because this is the output I'm currently getting: 567898765 45678987654 3456789876543 ...
1vote
1answer
49views
Inconsistent output given by same code on different C compilers
Different compilers are giving different outputs for the same logic in my algorithm. I wrote the following code for a C code exercise. The code checks for the longest string in a string vector. But ...
1vote
0answers
40views
Why just looping the last input?
so I wanna make a program to find each sum of the columns of a matrix. In this code first you can input how many matrix you want and the second input is the size of matrix (n x n) and third input is ...
-1votes
1answer
84views
How to get 2d array from a string (whole sentence) (each word a separate row)?
I've got some homework for my university subject, this is just a one part of the code that I don't know what is the most efficient way that I could use in the future and also to understand it fully. I ...
0votes
1answer
504views
c program: for loop rows and columns
I want to know how the modulo operator is used here Input and output are as follows: Input : 6 1 2 3 4 5 6 2 3 4 5 6 7 3 4 5 6 7 8 4 5 6 7 8 9 5 6 7 8 9 0 6 7 8 9 0 1 #include <stdio.h> int ...